package com.pacy.pacybaseproject.activitys;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
import com.blankj.utilcode.util.FragmentUtils;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.pacy.pacybaseproject.BR;
import com.pacy.pacybaseproject.R;
import com.pacy.pacybaseproject.base.BaseXActivity;
import com.pacy.pacybaseproject.beans.TabBean;
import com.pacy.pacybaseproject.databinding.ActivityBusMapBinding;
import com.pacy.pacybaseproject.viewmodels.BusMapViewModel;

import java.util.ArrayList;
import java.util.List;

/**
 * 附近公交
 */
public class BusMapActivity extends BaseXActivity<ActivityBusMapBinding, BusMapViewModel> {
    public List<LatLng> stations=new ArrayList<>();
private BaiduMap mBaiduMap;
    private ArrayList<CustomTabEntity> tabs = new ArrayList<>();
    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_bus_map;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        super.initData();
        setToolbar(binding.baseToolBar);
        mBaiduMap=binding.mapView.getMap();
        initMapState();
        initTab();
//        initLine();
    }

    private void initTab(){
        tabs.add(new TabBean("附近公交"));
        tabs.add(new TabBean("我的关注"));
        binding.tabLayout.setTabData(tabs);
        binding.tabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
//                startActivity(BusMapActivity.class);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
        binding.tabLayout.setCurrentTab(0);
    }

    public void initMapState(){
//        viewModel.aMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(39.538515,116.686093)));
//        viewModel.aMap.moveCamera(CameraUpdateFactory.zoomTo(17));//放大比例尺
//
//        LatLng latLng = new LatLng(39.538515,116.686093);
//        MarkerOptions markerOption = new MarkerOptions();
////                    markerOption.title(record.getTitle());
//        markerOption.icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_marker));
//        // 将Marker设置为贴地显示，可以双指下拉地图查看效果
//        markerOption.setFlat(true);//设置marker平贴地图效果
//        viewModel.aMap.addMarker(markerOption.position(latLng));
//
//        stations.add(new LatLng(39.5377,116.686908));
//        stations.add(new LatLng(39.53897,116.684945));
//        for (int i = 0; i < stations.size(); i++) {
//            View markerView = ViewGroup.inflate(BusMapActivity.this, R.layout.busstation_maker_view, null);
//            TextView name = markerView.findViewById(R.id.mk_tv);
//            if(i==0){
//                name.setText("西务");
//            }else{
//                name.setText("市信访局(广阳眼科医院)");
//            }
//
//            MarkerOptions icon = new MarkerOptions().position(stations.get(i)).icon(BitmapDescriptorFactory.fromView(markerView));
//            Marker marker = viewModel.aMap.addMarker(icon.position(stations.get(i)));
//            marker.showInfoWindow();
//        }


        MapStatus.Builder builder = new MapStatus.Builder();
        builder.zoom(16.0f);
        mBaiduMap.setMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
        //开起交通图
        mBaiduMap.setTrafficEnabled(true);
        //打开地图定位图层
        mBaiduMap.setMyLocationEnabled(true);

        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newLatLng(new LatLng(39.538515,116.686093)));

//        //定义Maker坐标点
//        LatLng point = new LatLng(39.537967,116.685658);
//        //构建Marker图标
//        BitmapDescriptor bitmap = BitmapDescriptorFactory
//                .fromResource(R.drawable.icon_marker);
//        //构建MarkerOption，用于在地图上添加Marker
//        OverlayOptions option = new MarkerOptions()
//                .position(point)
//                .icon(bitmap);
//        //在地图上添加Marker，并显示
//        mBaiduMap.addOverlay(option);


        stations.add(new LatLng(39.5377,116.686908));
        stations.add(new LatLng(39.53897,116.684945));
        for (int i = 0; i < stations.size(); i++) {
            View markerView = ViewGroup.inflate(BusMapActivity.this, R.layout.busstation_maker_view, null);
            TextView name = markerView.findViewById(R.id.mk_tv);
            if(i==0){
                name.setText("西务");
            }else{
                name.setText("市信访局(广阳眼科医院)");
            }

            MarkerOptions icon = new MarkerOptions().position(stations.get(i)).icon(BitmapDescriptorFactory.fromView(markerView));
            //构建MarkerOption，用于在地图上添加Marker
            OverlayOptions option = new MarkerOptions()
                    .position(stations.get(i))
                    .icon(icon.getIcon());
            //在地图上添加Marker，并显示
            mBaiduMap.addOverlay(option);
        }

    }



    private void initLine(){
//        List<LatLonPoint> pointList = new ArrayList<>();
//        pointList.add(new LatLonPoint(45.775461,126.668084));
//        pointList.add(new LatLonPoint(45.780235,126.673535));
//        pointList.add(new LatLonPoint(45.784829,126.678277));
//        pointList.add(new LatLonPoint(45.783332,126.685648));
//        pointList.add(new LatLonPoint(45.77799,126.689832));
//        pointList.add(new LatLonPoint(45.772869,126.691322));
//        pointList.add(new LatLonPoint(45.76742,126.692674));
//        pointList.add(new LatLonPoint(45.765669,126.678812));
//        pointList.add(new LatLonPoint(45.770788,126.678383));
//
//        List<BusStationItem> busStationItemList = new ArrayList<>();
//
//        BusStationItem item1 = new BusStationItem();
//        BusStationItem item2 = new BusStationItem();
//        BusStationItem item3 = new BusStationItem();
//        BusStationItem item4 = new BusStationItem();
//        BusStationItem item5 = new BusStationItem();
//        BusStationItem item6 = new BusStationItem();
//        BusStationItem item7 = new BusStationItem();
//        BusStationItem item8 = new BusStationItem();
//        BusStationItem item9 = new BusStationItem();
//
//        item1.setBusStationName("车站1");
//        item2.setBusStationName("车站2");
//        item3.setBusStationName("车站3");
//        item4.setBusStationName("车站4");
//        item5.setBusStationName("车站5");
//        item6.setBusStationName("车站6");
//        item7.setBusStationName("车站7");
//        item8.setBusStationName("车站8");
//        item9.setBusStationName("车站9");
//
//        item1.setLatLonPoint(new LatLonPoint(45.775461,126.668084));
//        item2.setLatLonPoint(new LatLonPoint(45.780235,126.673535));
//        item3.setLatLonPoint(new LatLonPoint(45.784829,126.678277));
//        item4.setLatLonPoint(new LatLonPoint(45.783332,126.685648));
//        item5.setLatLonPoint(new LatLonPoint(45.77799,126.689832));
//        item6.setLatLonPoint(new LatLonPoint(45.772869,126.691322));
//        item7.setLatLonPoint(new LatLonPoint(45.767076,126.690356));
//        item8.setLatLonPoint(new LatLonPoint(45.765669,126.678812));
//        item9.setLatLonPoint(new LatLonPoint(45.770788,126.678383));
//
//
//        busStationItemList.add(item1);
//        busStationItemList.add(item2);
//        busStationItemList.add(item3);
//        busStationItemList.add(item4);
//        busStationItemList.add(item5);
//        busStationItemList.add(item6);
//        busStationItemList.add(item7);
//        busStationItemList.add(item8);
//        busStationItemList.add(item9);
//
//
//        BusLineItem busLineItem = new BusLineItem();
//        busLineItem.setDirectionsCoordinates(pointList);
//        busLineItem.setBusStations(busStationItemList);
//
//        BusLineOverlay busLineOverlay = new BusLineOverlay(this, viewModel.aMap, busLineItem);
//        busLineOverlay.removeFromMap();
//        busLineOverlay.addToMap();
//        busLineOverlay.zoomToSpan();

    }





}